[Quartz Bug 663182] NSImage throws an exception from _gtk_quartz_create_image_from_pi...
authorJohn Ralls <jralls@ceridwen.us>
Mon, 7 Nov 2011 22:25:08 +0000 (14:25 -0800)
committerJohn Ralls <jralls@ceridwen.us>
Mon, 7 Nov 2011 22:25:08 +0000 (14:25 -0800)
If a zero-sized NSImage calls lockfocus it throws an exception. Make sure that the image isn't zero-sized before calling lockfocus, and log a warning and return NULL if it is zero-sized.

Have the quartz version of gtk_drag_begin_idle return FALSE if the returned image is NULL.

gtk/gtkdnd-quartz.c
gtk/gtkquartz.c

index 0653261c65268f66da46f2537d781e2c4a85230a..90506c1b9ee657a829ab0bb3643e629f6c985a98 100644 (file)
@@ -1081,6 +1081,11 @@ gtk_drag_begin_idle (gpointer arg)
   point = [info->nsevent locationInWindow];
 
   drag_image = _gtk_quartz_create_image_from_pixbuf (info->icon_pixbuf);
+  if (drag_image == NULL)
+    {
+      g_object_unref (info->context);
+      return FALSE;
+    }
 
   point.x -= info->hot_x;
   point.y -= info->hot_y;
index 74570005cd4a093ed40aa0809cad8536efcb6680..30261ff32468005b67a251ec12cb392efa4e3ce7 100644 (file)
@@ -35,9 +35,11 @@ _gtk_quartz_create_image_from_pixbuf (GdkPixbuf *pixbuf)
   int rowstride, pixbuf_width, pixbuf_height;
   gboolean has_alpha;
   NSImage *nsimage;
+  NSSize nsimage_size;
 
   pixbuf_width = gdk_pixbuf_get_width (pixbuf);
   pixbuf_height = gdk_pixbuf_get_height (pixbuf);
+  g_return_val_if_fail (pixbuf_width == 0 || pixbuf_height == 0, NULL);
   rowstride = gdk_pixbuf_get_rowstride (pixbuf);
   has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
 
@@ -57,6 +59,13 @@ _gtk_quartz_create_image_from_pixbuf (GdkPixbuf *pixbuf)
   CGColorSpaceRelease (colorspace);
 
   nsimage = [[NSImage alloc] initWithSize:NSMakeSize (pixbuf_width, pixbuf_height)];
+  nsimage_size = [nsimage size];
+  if (nsimage_size.width == 0.0 && nsimage_size.height == 0.0)
+    {
+      [nsimage release];
+      g_critical ("%s returned a zero-sized image", G_STRFUNC);
+      return NULL;
+    }
   [nsimage lockFocus];
 
   context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];